<?php
use yii\helpers\Html;
use yii\helpers\Url;
use app\lib\WeixinUtils;
/* @var $this yii\web\View */
/* @var $content string 字符串 */


$imgUrl=Url::to("@web/img/wx/");
$jsUrl=Url::to("@web/js/wx/");
$basejsUrl=Url::to("@web/js/");
$cssUrl=Url::to("@web/css/wx/");

?>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <title>确认兑换</title>
    <link rel="stylesheet" href="<?=$cssUrl?>/confirm_convert.css" />
    <link rel="stylesheet" href="<?=$cssUrl?>/weui.css" />
    <script src="<?=$basejsUrl?>/jquery.js"></script>
    <script src="<?=$basejsUrl?>/tools.js"></script>
    <script src="<?=$jsUrl?>/zepto.min.js"></script>
    <style type="text/css">
        .top_gb {
            background-image: url(<?=$imgUrl?>/confirm_convert_img/rack.png);
        }
        .goods_left{
            background-image: url("<?=$good['GOODS_IMG_URL']?>");
        }
    </style>
    <script>
	


        $(function($){
            $("#btn_exec").click(function(){
                var data={};
                data.CREMARK="";
                data.card_code_id='<?=$card_code_id?>';
                data.good_code='<?=$good['GOODS_CODE']?>';
                data.RECEIVERNAME=$('#txt_RECEIVERNAME').val();
                data.RECEIVERPHONE=$('#txt_RECEIVERPHONE').val();
                data.RECEIVERADDRESS=   $('#txt_RECEIVERADDRESS').val();
                data.sheng= $("#sel_sheng").find("option:selected").text();
                data.shi= $("#sel_shi").find("option:selected").text();
                data.qu= $("#sel_qu").find("option:selected").text();
                //校验

                if(data.sheng._trim()==''){
                    alert("省必须填写!");
                    return;
                }
                if(data.shi._trim()==''){
                    alert("市必须填写!");
                    return;
                }
                if(data.qu._trim()==''){
                    alert("区/县必须填写!");
                    return;
                }

                if(data.RECEIVERNAME._trim()==''){
                    alert("我的姓名必须填写!");
                    return;
                }
                if(data.RECEIVERPHONE._trim()==''){
                    alert("手机号码必须填写!");
                    return;
                }else{
					if(checkMobile(data.RECEIVERPHONE._trim())==false){
						alert("请填写正确手机号!");
						return;
					}
				}
                if(data.RECEIVERADDRESS._trim()==''){
                    alert("详细地址必须填写!");
                    return;
                }
                //下订单
                var re=returnjson("<?=Url::to(["wx-biz/submit-order-handle"])?>",data);
//                alert(JSON.stringify(re) );
//                return;
                if(re.flag==1){
                    alert("兑换成功");
                    window.location.href="<?=Url::to(["wx-biz/good-submit-order-success"]);?>";

                    return;
                }else{
                    alert(re.msg);
                };
            });


            $("#sel_sheng").html("");
            $("#sel_shi").html("");
            $("#sel_qu").html("");
            var shengs=getAreaOther(null);

            if(shengs!=false){
                $.each(shengs, function (i,item) {
                    $("#sel_sheng").append("<option  value='"+item.PK_DEFDOC+"'>"+item.DOCNAME+"</option>");
                });
                $("#sel_sheng").val(null);
            }

            $("#sel_sheng").change(function(){
                var me=$(this);
                $("#sel_shi").html("");
                $("#sel_qu").html("");
                var shis=getAreaOther(me.val());
                if(shis!=false){
                    $.each(shis, function (i,item) {
                        $("#sel_shi").append("<option value='"+item.PK_DEFDOC+"'>"+item.DOCNAME+"</option>");
                    });
                    $("#sel_shi").val(null);
                }
            });

            $("#sel_shi").change(function(){
                var me=$(this);
                $("#sel_qu").html("");
                var shis=getAreaOther(me.val());
                if(shis!=false){
                    $.each(shis, function (i,item) {
                        $("#sel_qu").append("<option value='"+item.PK_DEFDOC+"'>"+item.DOCNAME+"</option>");
                    });
                    $("#sel_qu").val(null);
                }
            });
        });

        function getAreaOther(pk){
            var data={};
            data.pk=pk;
            var re=returnjson("<?=Url::to(["wx-biz/get-area-handle"])?>",data);
            if(re.flag==1){
                return re.others;
            }else{
                alert(re.msg);
                return false;
            }
        }


    </script>
</head>

<body style="background-color:#FFFFFF;">

<div class="main">

<!--    <div class="top_title">
        <h3 class="top_text">兑换礼物</h3>
    </div>
-->
    <div class="top_gb">
        <div class="goods">
            <div class="goods_left"></div>
            <div class="goods_right">
                <div class="goods_right_title"><b><?=$good['GOODS_NAME']?></b></div>
                <div class="goods_right_text" style="font-size:0.6em;">本网站所售产品均为厂商正品，如有任何问题可与我们客服人员联系。</div>
            </div>
        </div>
    </div>

    <div class="input_name">
        <table class="input_address" cellpadding="0" cellspacing="0" border="0" width="320px" style="text-align:center; border-collapse:collapse;border-spacing:0; border-color:rgb(219,219,219);" rules="cols">
            <tr>
                <td width="80"><font style="color:rgb(64,64,64);"><b>我的姓名</b></font></td>
                <td><input class="text" type="text" id="txt_RECEIVERNAME"/></td>
            </tr>
        </table>

        <table class="input_address" cellpadding="0" cellspacing="0" border="0" width="320px" style="text-align:center; border-collapse:collapse;border-spacing:0; border-color:rgb(219,219,219);" rules="cols">
            <tr>
                <td width="80"><font style="color:rgb(64,64,64);"><b>手机号码</b></font></td>
                <td><input class="text" type="tel" id="txt_RECEIVERPHONE"/></td>
            </tr>
        </table>

        <table class="input_address" cellpadding="0" cellspacing="0" border="0" width="320px" style="text-align:center; border-collapse:collapse;border-spacing:0; border-color:rgb(219,219,219);" rules="cols">
            <tr>
			<td width="80"><font style="color:rgb(64,64,64);"><b>省</b></font></td>
                <td>
                    <select id="sel_sheng" style="height:40px; width:220px; border-top-style: none; border-right-style: none; border-left-style:none; border-bottom-style: none;">
                        <optgroup label="请选择">
                            <option value="1">zzz</option>
                        </optgroup>
                    </select>
                </td>
			</tr>
		</table>
		<table class="input_address" cellpadding="0" cellspacing="0" border="0" width="320px" style="text-align:center; border-collapse:collapse;border-spacing:0; border-color:rgb(219,219,219);" rules="cols">
			<tr>
			<td width="80"><font style="color:rgb(64,64,64);"><b>市</b></font></td>
                <td>
                    <select id="sel_shi" style="height:40px; width:220px; border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none;">
                        <optgroup label="请选择">
                            <option value="1">zzz</option>
                            <option value="2">aaaa</option>
                        </optgroup>
                    </select>
                </td>
			</tr>
		</table>
		<table class="input_address" cellpadding="0" cellspacing="0" border="0" width="320px" style="text-align:center; border-collapse:collapse;border-spacing:0; border-color:rgb(219,219,219);" rules="cols">
			<tr>
			<td width="80"><font style="color:rgb(64,64,64);"><b>区</b></font></td>
                <td>
                    <select id="sel_qu" style="height:40px; width:220px; border-top-style: none; border-right-style: none; border-left-style: none; border-bottom-style: none; ">
                        <optgroup label="请选择">
                            <option value="1">金牛</option>
                            <option value="2">成华</option>
                        </optgroup>
                    </select>
                </td>
            </tr>
        </table>
		
		<table class="input_address" cellpadding="0" cellspacing="0" border="0" width="320px" style="text-align:center; border-collapse:collapse;border-spacing:0; border-color:rgb(219,219,219);" rules="cols">
            <tr>
                <td width="80"><font style="color:rgb(64,64,64);"><b>详细地址</b></font></td>
                <td><textarea class="text" type="text" id="txt_RECEIVERADDRESS" style="height:60px; padding-top:10px;"></textarea></td>
            </tr>
        </table>
    </div>

<!--    <div class="address">
        <input class="text_msg" type="text" placeholder="&nbsp;&nbsp;&nbsp;详细地址" id="txt_RECEIVERADDRESS"/>
    </div>
-->

    <div class="down">
        <a href="javascript:;" class="but weui_btn weui_btn_primary" id="btn_exec">确认兑换</a>
    </div>

</div>

</body>
</html>

